package com.fenqing.leetcode.code.t0_200.t0_100;

import com.fenqing.annotations.Execute;
import com.fenqing.core.Topic;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author fenqing
 */
public class Topic001 extends Topic {
    /**
     * 构造器
     *
     * @param input1 输入
     */
    public Topic001(String input1, String input2) {
        super(input1, input2);
    }

    @Execute
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> hash = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            Integer integer = hash.get(nums[i]);
            if (integer != null) {
                return new int[]{integer, i};
            } else {
                hash.put(target - nums[i], i);
            }
        }
        return new int[]{};
    }

    public static void main(String[] args) {
        Topic001 topic001 = new Topic001("""
                [2,7,11,15]
                """, """
                9
                """);
        int[] run = topic001.run();
        System.out.println(Arrays.toString(run));
    }

}
